Repository navigation
Test: Fuzz the URL, header and body redaction - #520
ModeSevenIndustrialSolutions merged 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fuzz harness can exceed the 2 GiB per-input memory limit, and its incomplete independent header catalogue and restricted selector leave redaction regressions undetected.
2 open issues
What changed in this PR
Adds fuzz coverage for URL, header and body redaction, addressing issue #517 and fixing defects found by the harnesses.
Changes:
- Adds two Atheris harnesses with seed replay and oracle checks.
- Preserves IPv6 brackets and port zero during URL redaction.
- Redacts padded secret headers and handles JSON parsing limits.
| File | Description |
|---|---|
| tests/test_http_api_tool.py | Adds seed replay, oracle checks and regression tests. |
| tests/fuzz/fuzz_url_redaction.py | Fuzzes URL redaction, parsing and credential extraction. |
| tests/fuzz/fuzz_header_body_redaction.py | Fuzzes header and body redaction. |
| src/http_api_tool/sanitize.py | Fixes URL reconstruction and header sanitization edge cases. |
| README.md | Documents harness coverage and invocation. |
Review effort: Balanced
12fa4c4 to
87eef51
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Early-return exemptions in both fuzz targets bypass strict UTF-8 output checks for surrogateescaped inputs, leaving the unencodable-output logging path untested despite issue #517’s requirement.
1 open issue
Review effort: Balanced
87eef51 to
1059126
Compare
1059126 to
74ba815
Compare
74ba815 to
e6b2321
Compare
e6b2321 to
9919b20
Compare
There was a problem hiding this comment.
🤖 Antagonistic review by agent: 1 finding(s) for the human reviewer.
The production changes are focused, but the header fuzz oracle can report false failures at the JSON recursion boundary.
Antagonistic round 1 of 3. Revision requested from Code Monkey.
Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.
Add two Atheris harnesses under tests/fuzz/ for the redaction helpers in sanitize.py. Each oracle compares the whole result with an independent expectation: the redacted URL keeps the host, port, path and query and drops the credentials; every secret header is redacted, every other value kept, and no exception escapes; a body with a sensitive word is withheld and the rest truncated. The normal suite replays every seed and proves each oracle rejects a wrong result. Seeds that reproduce a defect fixed later on this branch are marked xfail(strict=True). The README says how to run the harnesses by hand. Review round 1: - The header catalogue lacked auth, bearer, access-token and x-session-token, and its selector reached eight names. It now holds all twelve, a four-bit selector reaches each, and the oracle requires redaction for any name in it or in the module's list, so dropping one from the module fails the harness. - A short input could ask for 600 values a million brackets deep, over 2 GiB. Generated digits and brackets now share a 4,000,000 character budget per input; that input is a seed. - basedpyright saw "listed" as possibly unbound after pytest.skip in the discovery test; the check now sits in the try's else. Review round 2: - emit() skipped the strict UTF-8 stream for undecodable input, so a redacted value holding a lone surrogate was never shown. Both harnesses now write every shown value, parse_url's parts too, and expect U+FFFD for each lone surrogate. Five undecodable seeds are xfail until the fix later on this branch. Review round 3: - The raw-URL oracle for parse_url never checked protocol, path, query or fragment, so a parse_url that dropped a query passed. It now compares all four, typed, with the displayable input parsed independently. Negative controls cover each field, a URL with params, query and fragment, and undecodable input; the stale path in the reused fixture is gone. Review round 4: - The body catalogue planted api_key, where the module withholds any body holding key, and the raw-body oracle trusted the module's list. Narrowing it from key to api_key exposed bodies with key unseen. The catalogue now plants key, and the oracle withholds a body holding a word from it or the module's list. A test shows an empty or narrowed module list fails the oracle. Review round 5: - The README said extract_url_credentials drops the credentials from a URL, but it returns them and must not be logged. The README now names only sanitize_url_for_logging and parse_url as redacting, and says the harness checks the extracted pair and never shows it. Antagonistic review round 1: - On Python 3.11 the JSON decoder shares the recursion limit, and the header oracle decoded one call deeper than production. A secret header nested at production's limit was decoded and redacted, but the oracle ran out of room and called the input invalid. It now decodes and compares with 50 frames more room, treats running out despite that as its own case, and accepts the placeholder for a decoded object only if it cannot show it with 50 frames less. Planted depths are little-endian, so depths near the limits of 3.11 to 3.13 are reachable. A test checks the oracle at its own limit; another, xfail until the fix later on this branch, replays a secret header around production's limit. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
sanitize_url_for_logging rebuilt the netloc from parsed.hostname, which urlparse returns without the brackets of an IPv6 literal, and kept the port only when it was truthy. A redacted IPv6 URL lost its brackets and so its port, and port 0 vanished. parse_url had the bracket fix already; both now share one helper. The fuzzer also found host names that hold a bracket outside an IP literal, such as "v1.[". No rebuilt URL with such a host parses, so the helper refuses it: sanitize_url_for_logging shows its placeholder and parse_url raises ValueError, as it already does for other malformed URLs. The parse_url docstring now says so. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
sanitize_headers_for_logging matched a header name exactly, so "X-Api-Key " or "\tCookie" kept its secret in the log, while curl sends the name as written and a lenient server may trim it. It now matches the name with surrounding whitespace removed. It also let two decoder limits escape: ValueError for an integer past the int digit limit and RecursionError for deep nesting. Both now give the invalid-JSON placeholder, as other bad input does. The header seeds in the seed replay lose their xfail markers. The test that replays a secret header nested around the depth this code can decode loses its xfail marker too, and three seeds plant one near that depth on Python 3.11, 3.12 and 3.13, and 3.14. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
os.environ turns bytes that are not UTF-8 into lone surrogates, and the redaction helpers passed them through. A strict UTF-8 stdout, as under en_US.UTF-8, then refused the line: the CLI died with UnicodeEncodeError while logging the redacted URL or request body, so the module's promise that every value it returns is safe to display did not hold. sanitize_url_for_logging, sanitize_request_body_for_logging and the display values of parse_url now replace each lone surrogate with U+FFFD. Truncation still counts input characters, and the sensitive word check still reads the body as given. Headers already come back through json.dumps, which escapes them. The undecodable seeds lose their xfail markers, and a regression test logs the CLI configuration on a strict UTF-8 stdout. Co-authored-by: Copilot <[email protected]> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
9919b20 to
247bbe7
Compare
There was a problem hiding this comment.
🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.
The redaction fixes and fuzz harnesses are consistent with the inspected callers and regression tests. No actionable defects found in this diff.
Antagonistic round 2 of 3.
Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.
fdde9c2
into
lfreleng-actions:main


Closes #517
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLIffa820860707ab434f947177e7c0022d6d8cd00fuv run python .scratch/repro.py (3.11, 3.12, 3.13, 3.14; reproduces the finding on 3.11)UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 pytest -q --no-cov tests/test_http_api_tool.py -k 'decoder_limit or own_limit' (old oracle restored; must fail)uv run --frozen pytest -q (at 1ce9467)uv run --frozen pytest -q (at 01d2a93)uv run --frozen pytest -q (at ebb2918)uv run --frozen pytest -q (at f4f3c11)UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 pytest -qUV_PROJECT_ENVIRONMENT=.scratch/venv3.12 uv run --frozen --python 3.12 pytest -quv run --frozen --python 3.14 --isolated --extra test pytest -q --no-cov tests/test_http_api_tool.py -k 'Fuzz or Regression'uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/* (3.13, 438 boundary inputs)uv run --frozen --python 3.11 --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/* (3.11, 438 boundary inputs)uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py -max_total_time=70 -rss_limit_mb=2048 .scratch/c313UV_PROJECT_ENVIRONMENT=.scratch/venv3.11 uv run --frozen --python 3.11 --with atheris python tests/fuzz/fuzz_header_body_redaction.py -max_total_time=70 -rss_limit_mb=2048 .scratch/c311buv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py -runs=0uv run --frozen --with atheris python tests/fuzz/fuzz_header_body_redaction.py .scratch/win/raw992python3 monkey-assets/scripts/message_check.py ffa820860707ab434f947177e7c0022d6d8cd00fAISLOP_NO_TELEMETRY=1 uv run --frozen --with ruff npx -y [email protected] scan --changes --base ffa820860707ab434f947177e7c0022d6d8cd00f --ruff project --jsonprek run --files README.md src/http_api_tool/sanitize.py tests/fuzz/fuzz_header_body_redaction.py tests/fuzz/fuzz_url_redaction.py tests/test_http_api_tool.py (before fixup; ruff-format rewrapped a laprek run --files README.md src/http_api_tool/sanitize.py tests/fuzz/fuzz_header_body_redaction.py tests/fuzz/fuzz_url_redaction.py tests/test_http_api_tool.pyThe
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.
Round 6 of revision, on its base. It answers antagonistic review round 1: #520 (review).
Adds two Atheris fuzz harnesses for the redaction helpers in
src/http_api_tool/sanitize.py. It also fixes the contract breaches they found, with each fix in its own commit.Commits
Test: Fuzz the URL, header and body redaction: addstests/fuzz/fuzz_url_redaction.pyandtests/fuzz/fuzz_header_body_redaction.py(harness contract v1). It adds a seed replay with a negative control for each oracle totests/test_http_api_tool.py, and a README section. Seeds for defects fixed later on the branch arexfail(strict=True)until their fix.Fix: Keep the host and port in redacted URLs: keeps the IPv6 brackets and port 0, and refuses a host that holds a stray bracket.Fix: Redact padded headers, contain JSON limits: matches header names with surrounding whitespace trimmed. The integer digit limit (ValueError) and deep nesting (RecursionError) now give the invalid-JSON placeholder.Fix: Show undecodable input as U+FFFD in logs: shows lone surrogates as U+FFFD, so a strict UTF-8 stdout can print every displayed value.Antagonistic review (this round)
On Python 3.11, the JSON decoder counts nesting against the interpreter recursion limit. The header oracle decoded one call deeper than production. Reproduced: at depth 992, production decoded and redacted a nested
Authorizationvalue, but the oracle hitRecursionErrorand reported "no placeholder for non-object". Python 3.12 to 3.14 were not affected. Fixed in commit 1:ORACLE_ROOM(50) frames more recursion room than production has.OracleExhaustedis a separate case: running out despite that room is not treated as invalid input. That input must get the placeholder, because production has less room.Authorizationheader, raw and planted, throughcheck_one_inputat every depth within 50 of production's limit. It is xfail in commit 1, and commit 3 removes the marker and adds three planted seeds at depths 992, 9,996 and 116,121.Validation
uv run pytest: 124 passed at the head. Each commit passes on its own (92/102/117/124 passed, with the expected xfails). The suite also passes on Python 3.11 and 3.12, and the fuzz tests pass on 3.14.prek run --files <changed files>: exit 0. aislop 0.24 (--ruff project): 0 diagnostics, score 100. Commit message check: exit 0.-runs=0and single-file replay: exit 0. The URL harness did not change this round.For the reviewer
sys.setrecursionlimit. On 3.12 and later the decoder's nesting has its own C budget, so the room has no effect there, and the oracle and production have the same budget.